﻿Imports System.Windows.Forms
Imports System.Drawing

Public Class frmCarga
    Private Sub cmdCargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MessageBox.Show("Se leyeron 5000 registros y se grabaron 5000 registros", TitMsj, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub tvwCarga_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs)
        If tvwCarga.SelectedNode.Name = "tvwCarga" Then
            cmdCargar.Enabled = True
        ElseIf tvwCarga.SelectedNode.Text = "Curvas" Then
            cmdCargar.Enabled = True
        ElseIf tvwCarga.SelectedNode.Text = "Monedas" Then
            cmdCargar.Enabled = True
        ElseIf tvwCarga.SelectedNode.Text = "Indice/Precios" Then
            cmdCargar.Enabled = True
        ElseIf tvwCarga.SelectedNode.Text = "Data Manager" Then
            Dim oForm As New frmDataManager
            oForm.Show()
        Else
            'cmdCargar.Enabled = False
        End If
    End Sub

    Private Sub frmCarga_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'cmdCargar.Enabled = False
        Armar_Grilla()
    End Sub

    Private Sub Armar_Grilla()
        Dim dtPortaf As New DataTable
        Dim dsPortaf As New DataSet

        Dim dr, dr2, dr3 As DataRow

        dtPortaf.Columns.Add("Instrumento")
        dtPortaf.Columns.Add("Cartera")
        dtPortaf.Columns.Add("Corporación")
        dtPortaf.Columns.Add("Mesa")
        dtPortaf.Columns.Add("Cta Contable")
        dtPortaf.Columns.Add("Mto Nominal")

        dr = dtPortaf.NewRow
        dr2 = dtPortaf.NewRow
        dr3 = dtPortaf.NewRow

        dr(0) = "PERV_001"""
        dr(1) = "Disp. Venta"
        dr(2) = "BCP"
        dr(3) = "M120"
        dr(4) = "125896478512"
        dr(5) = "1,528.25"

        dtPortaf.Rows.Add(dr)

        dr2(0) = "CDBCRP"
        dr2(1) = "Disp. Venta"
        dr2(2) = "BCP"
        dr2(3) = "M120"
        dr2(4) = "125896478512"
        dr2(5) = "327,894.25"

        dtPortaf.Rows.Add(dr2)

        dr3(0) = "CA02547888"
        dr3(1) = "Disp. Venta"
        dr3(2) = "BCP"
        dr3(3) = "M120"
        dr3(4) = "125896478512"
        dr3(5) = "89,715.85"

        dtPortaf.Rows.Add(dr3)

        dsPortaf.Tables.Add(dtPortaf)

        dgCarga.DataSource = dsPortaf.Tables(0)

    End Sub

    Private Sub dgCarga_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
        Dim Colum, Fila As Integer
        Dim grid As DataGridView = sender
        Dim pt As Point = grid.PointToClient(Control.MousePosition)

        If e.Button = Windows.Forms.MouseButtons.Right Then
            Colum = e.ColumnIndex
            Fila = e.RowIndex
            If Colum < 0 Or Fila < 0 Then
                Exit Sub
            End If

            With Me.dgCarga
                Dim Hitest As DataGridView.HitTestInfo = .HitTest(e.X, e.Y)
                If Hitest.Type - 1 = DataGridViewHitTestType.Cell Then
                    .CurrentCell = .Rows(Fila).Cells(Colum)
                End If
            End With

            If dgCarga.AllowUserToAddRows = True Then

                If dgCarga.Rows.Count > 1 Then

                    Me.ContextMenuStrip1.Show(dgCarga, pt.X, pt.Y)

                End If

            Else

                If dgCarga.Rows.Count > 0 Then

                    Me.ContextMenuStrip1.Show(dgCarga, pt.X, pt.Y)

                End If

            End If
        End If
    End Sub

    Private Sub ExportarVolatilidadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportarVolatilidadToolStripMenuItem.Click
        Cursor = Cursors.WaitCursor
        Exportar_Excel(dgCarga)
        Cursor = Cursors.Default

    End Sub

    Private Sub dgCarga_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCarga.CellContentClick

    End Sub
End Class